package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduComment;
import com.atguigu.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-11-02
 */
@RestController
@RequestMapping("/eduservice/educomment")
public class EduCommentController {
    @Autowired
    EduCommentService commentService;

    //添加评论
    @PostMapping("addEduComment")
    public R addEduComment(@RequestBody EduComment eduComment) {
        commentService.save(eduComment);
        return R.ok();
    }

    //查看课程的所有的评论
    @GetMapping("getAllComment/{courseId}/{page}/{limit}")
    public R getAllComment(@PathVariable String courseId, @PathVariable long page, @PathVariable long limit) {
        Page<EduComment> commentPage = new Page<>(page, limit);
        Map<String, Object> map = commentService.getCouseCommentByConrseId(courseId, commentPage);
        return R.ok().data(map);
    }
}

